home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Utilities / Siege Watch 2.0 / Daemon.p next >
Encoding:
Text File  |  1994-04-23  |  4.0 KB  |  157 lines  |  [TEXT/PJMM]

  1. { unit to interface with Speech Daemon GH }
  2. unit Daemon;
  3. interface
  4.     uses
  5.         FixMath, Utility, Globals, Speech, PPCToolBox, Script, Processes;
  6.     procedure Talk2Daemon (prefs: PrefRecord;
  7.                                     string2Speak: Str255);
  8.     function IsDaemonAwake: Boolean;
  9. implementation
  10.  
  11.     type
  12.         MyVoiceInfo = record
  13.                 vers: integer;
  14.                 vol: Fixed;
  15.                 rate: Fixed;
  16.                 modu: Fixed;
  17.                 pit: Fixed;
  18.                 aVoice: VoiceSpec;
  19.                 theString: Str255;
  20.                 keepChannel: Boolean;
  21.                 waitTicks: LONGINT;
  22.                 currTicks: LONGINT;
  23.             end;
  24.         SessionRecord = record
  25.                 pb: PPCParamBlockRec;
  26.                 portName: PPCPortRec;
  27.                 locationName: LocationNameRec;
  28.                 userName: Str255;
  29.                 buf1: Str255;
  30.                 buf2: Str255;
  31.             end;
  32.     const
  33.         kDaemonVersion = 1;
  34.         kSpeakString = 1000;
  35.  
  36.  
  37.     function IsDaemonAwake: Boolean;
  38.         var
  39.             procNum: ProcessSerialNumber;
  40.             procInfo: ProcessInfoRec;
  41.             iErr: OSErr;
  42.             done: Boolean;
  43.     begin
  44.         procInfo.processInfoLength := sizeof(ProcessInfoRec);
  45.         procInfo.processName := nil;
  46.         procInfo.processAppSpec := nil;
  47.         procNum.highLongOfPSN := 0;
  48.         procNum.lowLongOfPSN := kNoProcess;
  49.         IsDaemonAwake := FALSE;
  50.         done := FALSE;
  51.         iErr := GetNextProcess(procNum);
  52.         while (iErr = noErr) and (done = FALSE) do
  53.             begin
  54.                 iErr := GetProcessInformation(procNum, procInfo);
  55.                 if iErr = noErr then
  56.                     begin
  57.                         if ('IF 8' = procInfo.processSignature) and ('APPL' = procInfo.processType) then
  58.                             begin
  59.                                 IsDaemonAwake := TRUE;
  60.                                 done := TRUE;
  61.                             end;
  62.                     end;
  63.                 iErr := GetNextProcess(procNum);
  64.             end;
  65.     end;
  66. { open a PPC port }
  67.     function OpenAPort (var refNum: integer): OSErr;
  68.         var
  69.             thePort: PPCPortRec;
  70.             pb: PPCOpenPBRec;
  71.             err: OSErr;
  72.             aString: Str255;
  73.     begin
  74.         thePort.nameScript := smRoman;
  75.         GetIndString(aString, 128, 2);
  76.         BlockMove(@aString, @thePort.name, 32);
  77.         thePort.portKindSelector := ppcByCreatorAndType;
  78.         thePort.portCreator := 'Slik';
  79.         thePort.PortType := 'APPL';
  80.         pb.ioCompletion := nil;
  81.         pb.serviceType := ppcServiceRealTime;
  82.         pb.resFlag := 0;
  83.         pb.networkVisible := false;
  84.         pb.portName := @thePort;
  85.         pb.locationName := nil;
  86.         err := PPCOpen(@pb, false);
  87.         OpenAPort := err;
  88.         refNum := pb.portRefNum;
  89.     end;
  90.  
  91.     procedure Talk2Daemon (prefs: PrefRecord;
  92.                                     string2Speak: Str255);
  93.         var
  94.             iErr: OSErr;
  95.             err: OSErr;
  96.             refNum: integer;
  97.             sesRec: SessionRecord;
  98.             myVInfo: MyVoiceInfo;
  99.             aString: Str255;
  100.     begin
  101.         iErr := OpenAPort(refNum);
  102.         if iErr = noErr then
  103.             begin
  104.                 sesRec.portName.nameScript := smRoman;
  105.                 GetIndString(aString, 128, 1);
  106.                 BlockMove(@aString, @sesRec.portName.name, 32);
  107.                 sesRec.portName.portKindSelector := ppcByCreatorAndType;
  108.  
  109.                 sesRec.portName.portCreator := 'IF 8';
  110.                 sesRec.portName.PortType := 'APPL';
  111.  
  112.                 sesRec.pb.startParam.ioCompletion := nil;
  113.                 sesRec.pb.startParam.portRefNum := refNum;
  114.                 sesRec.pb.startParam.serviceType := ppcServiceRealTime;
  115.                 sesRec.pb.startParam.resFlag := 0;
  116.                 sesRec.pb.startParam.portName := @sesRec.portName;
  117.  
  118.                 sesRec.pb.startParam.locationName := nil;
  119.                 sesRec.pb.startParam.userData := kSpeakString;
  120.                 sesRec.pb.startParam.userRefNum := 0;
  121.  
  122.  
  123.                 iErr := PPCStart(@sesRec.pb.startParam, FALSE);
  124.                 if iErr = noErr then
  125.                     begin
  126.                         with myVInfo, prefs do
  127.                             begin
  128.                                 vers := kDaemonVersion;
  129.                                 vol := volume;
  130.                                 rate := wpm;
  131.                                 modu := modulation;
  132.                                 pit := pitch;
  133.                                 aVoice.creator := voice.creator;
  134.                                 aVoice.id := voice.id;
  135.                                 waitTicks := 0;
  136.                                 currTicks := TickCount;
  137.                                 keepChannel := keepVoice;
  138.                             end;
  139.                         BlockMove(@string2Speak, @myVInfo.theString, 255);
  140.                         sesRec.pb.writeParam.ioCompletion := nil;
  141.                         sesRec.pb.writeParam.bufferLength := sizeof(MyVoiceInfo);
  142.                         sesRec.pb.writeParam.bufferPtr := Ptr(@myVInfo);
  143.                         sesRec.pb.writeParam.more := false;
  144.                         iErr := PPCWrite(@sesRec.pb.writeParam, FALSE);
  145.                     end;
  146.  
  147.                 err := PPCEnd(@sesRec.pb.endParam, false);
  148.                 err := PPCClose(@sesRec.pb.closeParam, false); { close the port }
  149.             end;
  150. { if something failed, speak the string using the default method }
  151.  
  152.         if iErr <> noErr then
  153.             begin
  154.                 iErr := SpeakString(string2Speak);
  155.             end;
  156.     end;
  157. end.